/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//Author : Kyle Woodworth

window.onload = fixLoginBirth("register");

function fixLoginBirth(formString) {
    
    var form = document.forms[formString];
    
    //get the form and necessary selects
    var regForm = form
    var day = regForm.day;
    var month = regForm.month;
    var year = regForm.year;
    
    //find the current year and initiate a var to hold the "options"
    var currentYear = new Date().getFullYear();
    var years = "";
    
    //create options and place into select
    for(var i = currentYear; i > 1900; i--){
        years += "<option value="+i+">"+i+"</option>";
    }
    year.innerHTML = years;
    
    //initiate month to january and create var to hold day options
    month.selectedIndex = 0;
    var days = "";
    
    //create options for day and place into select
    for(i = 1; i <= 31; i++){
        days += "<option value="+i+">"+i+"</option>";
    }
    day.innerHTML = days;
}

function adaptDaysToMonth(formString){
    var form = document.forms[formString];
    var day = form.day;
    var month = form.month;
    var year = form.year;
    var selectedMonth = month.selectedIndex;
    var selectedDay = day.selectedIndex;
    var numDays;
    
    if(selectedMonth == 0 || selectedMonth == 2 || selectedMonth == 4 || selectedMonth == 6 || selectedMonth == 7 || selectedMonth == 9 || selectedMonth == 11){
        numDays = 31;
    }else if(selectedMonth == 3 || selectedMonth == 5 || selectedMonth == 8 || selectedMonth == 10){
        numDays = 30;
    }else if(selectedMonth == 1){
        numDays = 28;
    }
    
    if(numDays > selectedDay+1){
        day.selectedIndex = 0;
    }
    
    var newDays = "";
    
    for(var i = 1; i <= numDays; i++){
        newDays += "<option value="+i+">"+i+"</option>";
    }
    
    day.innerHTML = newDays;
}

